<?php
namespace App\Controllers;

use \Psr\Http\Message\ServerRequestInterface as Request;
use \Psr\Http\Message\ResponseInterface as Response;

use App\Models\RoleModel;
use stdClass;
class RoleController extends BaseController {
	public function getUpdate($request, $response, $args) {
		include APP_PATH . "Views/Role/roleupdata.html";
	}
	public function roleUpdate($request, $response, $args) {
		$username = $request -> getParam('username');
		$roleid = $request -> getParam('roleid');
		$user = new RoleModel();
		$data1 = $user -> roleupdata($username, $roleid);
		$msg = json_decode($data1);
		echo json_encode($msg);

	}

	public function getRole($request, $response, $args) {
		include APP_PATH . "Views/Role/rolelist.html";
	}

	public function RoleShow($request, $response, $args) {
		$roleid = $request -> getParam('roleid');
		 $user=new RoleModel();
        $result = $user->getCountRole($roleid);
		
		$draw=$request->getParam('draw')*1;//第几次请求
		$start=$request->getParam('start');//第一条数据开始的索引
		$length=$request->getParam('length');//返回的数据长度
		$newarr = new stdClass();
		$newarr->draw = $draw;
		$newarr->page = count($result)/$length;
		$newarr->recordsTotal = count($result);
		$newarr->recordsFiltered = count($result);
		$newarr->data = array();
		$h=0;
		for($i = $start; $i<$start+$length;$i++,$h++)
			{   if(!empty($result[$i])){
				$newarr->data[$h] = $result[$i];
				}else{
					break;
				}
						
			}
				return $newResponse = $response->withJson($newarr, 200);

	}

}
?>